﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace MTRC.ODMS.Web.SOM.Popup
{
    public partial class PopupHandOverCheck : BasePage_SOM
    {
        /// <summary>
        /// Mark whether
        /// </summary>
        public bool FlagHandover
        {
            get { return Convert.ToBoolean(ViewState["FlagHandover"].ToString()); }
            set { ViewState["FlagHandover"] = Convert.ToBoolean(value); }
        }

        /// <summary>
        /// StationEventID  ISU45
        /// add by gordon 20160215
        /// </summary>
        protected int StationEventID
        {
            get
            {
                //update by gordon 20160218 ISU45
                //if (ViewState[MTRC.ODMS.BLL.COM.Session.SOM_StationEventID] == null)
                //{
                //    return -1;
                //}
                //else
                //{
                //    return int.Parse(ViewState[MTRC.ODMS.BLL.COM.Session.SOM_StationEventID].ToString());
                //}
                int stationEventID = -1;
                int.TryParse(Request.QueryString["StationEventID"], out stationEventID);
                return stationEventID > 0 ? stationEventID : -1;
                //update end by gordon 20160218 ISU45
            }
            //Comment by gordon 20160218 ISU45
            //set
            //{
            //    ViewState[MTRC.ODMS.BLL.COM.Session.SOM_StationEventID] = value;
            //}
        }

        /// <summary>
        /// PageLoad event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetLanguage();
                BindHandOverInfo();
            }
        }

        /// <summary>
        /// Set page control language&init
        /// </summary>
        private void SetLanguage()
        {
            // remove dylan 20150826 for u168.8
            //this.chkHandoverCheck.Checked = true;
            //this.txtHandoverCheckDetail.Enabled = true;
            this.btnSave.Text = this.GetLabel("COM_Save", false);
            this.btnCancel.Text = this.GetLabel("COM_Cancel", false);
            lblHandoverCheck.Text = this.GetLabel("SOM_HandoverCheck", true) + "<em>*<em>";
        }

        /// <summary>
        /// Bind hand over information
        /// </summary>
        private void BindHandOverInfo()
        {
            using (SqlDataReader drHandOver = ODMS.BLL.SOM.Event.StationEventAdmReg.GetStationEventHandOver(this.StationEventID))
            {
                if (drHandOver.HasRows)
                {
                    drHandOver.Read();
                    FlagHandover = Convert.ToBoolean(drHandOver["FlagHandover"]);
                    this.chkHandoverCheck.Checked = FlagHandover;
                    this.txtHandoverCheckDetail.Text = drHandOver["HandoverNote"].ToString();
                }
            }
        }

        /// <summary>
        /// OnInit event
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //comment by gordon 20160218 ISU45
            //int stationEventID = -1;
            //int.TryParse(string.Concat(Request.QueryString["StationEventID"]).Trim(), out stationEventID);
            //this.StationEventID = stationEventID;
        }

        /// <summary>
        /// Save station event hand over note
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool IsFlagHandOverChecked = this.chkHandoverCheck.Checked ? true : false;
            string HandoverCheckDetail = this.txtHandoverCheckDetail.Text.Trim();
            if (string.IsNullOrEmpty(HandoverCheckDetail))
                return;
            ODMS.BLL.SOM.Event.StationEventAdmReg.UpdateStationEventHandOver(this.StationEventID, HandoverCheckDetail, IsFlagHandOverChecked, this.ODMUser.ID);
        }

        // remove by dylan 2050826 for u168.8
        ///// <summary>
        ///// hand over checked event
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void chkHandoverCheck_CheckedChanged(object sender, EventArgs e)
        //{
        //    if (chkHandoverCheck.Checked)
        //    {
        //        this.hidHandOverChecked.Value = "1";
        //        //txtHandoverCheckDetail.Enabled = true;
        //    }
        //    else
        //    {
        //        this.hidHandOverChecked.Value = "0";
        //        //if (this.FlagHandover)
        //        //{
        //        //    this.txtHandoverCheckDetail.Enabled = true;
        //        //}
        //        //else
        //        //{
        //        //    this.txtHandoverCheckDetail.Enabled = false;
        //        //}
        //    }
        //}
    }
}